import { Component, ViewChild } from '@angular/core';

import { UserRoleComponent } from './user.role.component';

declare var form: any;

@Component({
  templateUrl: './role.html'
})
export class RoleComponent {

  @ViewChild('userSelect', { static: true }) us: UserRoleComponent;

  services = [];
  menus = [];
  datas = [];
  mapLayers = [];
  mapExtents = [];

  fs: any = null;
  regDic: any = null;
  menuDic: any = null;
  dataDic: any = null;

  constructor() {
    this.fs = new form.FormTreeService('role', {
      orderObject: { order: 0 },
      keyField: 'id',
      randomFields: ['id'],
      pageSize: 1000,
      defaultObject: { leaf: false }
    });
    this.fs.loadData(true);

    // 初始化字典
    this.regDic = new form.DictionaryService('p_register_service');
    this.regDic.loadAll();

    this.menuDic = new form.DictionaryService('p_menu_jurisdiction');
    this.menuDic.loadAll();

    this.dataDic = new form.DictionaryService('p_data_jurisdiction');
    this.dataDic.loadAll();
  }

  checked(e, s: any[]) {
    const id = e.node.key;
    if (e.node.isChecked) {
      if (s.indexOf(id) === -1) {
        s.push(id);
      }
    } else {
      if (s.concat(id)) {
        s.splice(s.indexOf(id), 1);
      }
    }
  }
}
